import pandas as pd

# 读取 Excel 文件
excel_file = "C:/Users/jkbl/Desktop/20240123春节切换扫码模式湖南门店最新.xlsx"
df = pd.read_excel(excel_file)

# 提取某几列
selected_columns = ["名称", "key", "客服中心"]
nuw_columns = ["门店名称", "门店标识", "所属客服中心"]
selected_df = df[selected_columns].copy()  # Create a copy to avoid SettingWithCopyWarning

# 移除小数点并在 "key" 列左边补 0
selected_df["key"] = selected_df["key"].astype(str).str.split('.').str[0].apply(lambda x: x.zfill(10))

# 保存为 CSV 文件，保存列名为 nuw_columns，并指定分隔符为逗号
csv_file = "C:/Users/jkbl/Desktop/20240123春节切换扫码模式湖南门店最新.csv"
selected_df.to_csv(csv_file, index=False, header=False, sep=',')

# 打开保存的 CSV 文件，在首行插入新的列名
# Read the CSV file with explicit encoding
with open(csv_file, 'r', encoding='utf-8') as file:
    content = file.read()

# Write the modified content back to the CSV file
with open(csv_file, 'w', encoding='utf-8') as file:
    file.write(','.join(nuw_columns) + '\n' + content)
